mrgorunfandomcom_ru-20200214-history
Модуль:Feature
local lib = {} function lib.mergeFrames(frame, parent) local args = {} if frame then for k,v in pairs(frame.args) do argsk = v end end if parent then for k,v in pairs(parent.args) do argsk = v end end return args end function lib.arguments(origArgs) local args = {} for k, v in pairs(origArgs) do if v ~= '' then argsk = v end end return args end function lib.getSortedKeys(tab) local keys = {} for k,_ in pairs(tab) do keys#keys+1 = k end table.sort(keys) return keys end function lib.groupedArguments(args, numeric) if numeric nil then numeric = true end numeric = not not numeric local base = {} local groups = {} for k, v in pairs(args) do v = mw.text.trim(v) or '' if v ~= '' then if type(k) 'string' then k = mw.text.trim(k) or '' if k ~= '' then local split = mw.text.split(k, ':') if #split 1 then basek = v else local group = mw.text.trim(split1) or '' local key = mw.text.trim(table.concat(split, ':', 2)) or '' if key ~= '' and group ~= '' then if numeric then group = tonumber(group) if group ~= nil then if groupsgroup nil then groupsgroup = {} end groupsgroupkey = v else basek = v end else if groupsgroup nil then groupsgroup = {} end groupsgroupkey = v end else basek = v end end end elseif v ~= '' then basek = v end end end return base, groups end function lib.ternary(cond, T, F) if cond then return T else return F end end function lib.tbl_concat(frame) local args; if frame.args nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local pre = args"pre" or args"prepend" or "" local app = args"app" or args"append" or "" local sep = args"sep" or args"separator" or "," local tbl = args"tbl" or args1 local index = args"index" local s = "" if index ~= nil then s = s .. pre .. tbltonumber(index) .. app else for i, v in pairs(tbl) do if i ~= 1 then s = s .. sep end s = s .. pre .. v .. app end end return s end function lib.tbl_debug(tbl) return table.tostring(tbl) end -- Helper functions function table.val_to_str(v) if "string" type(v) then v = string.gsub(v, "\n", "\\n") if string.match(string.gsub(v, "^'\"", ""), '^"+$') then return "'" .. v .. "'" end return '"' .. string.gsub(v, '"', '\\"') .. '"' else return "table" type(v) and table.tostring(v) or tostring(v) end end function table.key_to_str(k) if "string" type(k) and string.match(k, "^_%a_%a%d*$") then return k else return ".. table.val_to_str(k) .. "" end end function table.tostring(tbl) local result, done = {}, {} for k, v in ipairs(tbl) do table.insert(result, table.val_to_str(v)) donek = true end for k, v in pairs(tbl) do if not donek then table.insert(result, table.key_to_str(k) .. "=" .. table.val_to_str( v )) end end return "{" .. table.concat(result, ",") .. "}" end function lib.validateName(_input) local champname = _input if champname "Nunu" or champname "Willump" then champname = "Nunu & Willump" end if champname "Quinn & Valor" or champname "Valor" then champname = "Quinn" end if champname "Shadow Assassin" or champname "Rhaast" then champname = "Kayn" end if champname "Lamb" or champname "Wolf" then champname = "Kindred" end return champname end return lib -- -- Category:Lua